package com.aaa.controller;

import com.aaa.entity.TabRoleMenu;
import com.aaa.service.ITabRoleMenuService;
import com.aaa.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 于永利
 * @since 2024-08-03
 */
@RestController
@RequestMapping("/tab-role-menu")
public class TabRoleMenuController {

    @Autowired
    private ITabRoleMenuService tabRoleMenuService;

    @GetMapping
    public Result getMidByRid(Integer rid){
        Map<String,Object> map = new HashMap<>();
        map.put("rid",rid);
        List<TabRoleMenu> tabRoleMenus = tabRoleMenuService.listByMap(map);

        return Result.success(tabRoleMenus);

    }

    // 根据角色的id删除对应的菜单的id
    // 添加这个角色选中的菜单的id
    @GetMapping("updPre")
    public Result updPre(Integer rid,String mids){
        List<String> list=new ArrayList<>();
       if(mids.length()>0){
           list = Arrays.asList(mids.split(","));
       }

       // List<String>   List<Integer>
        List<Integer> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            list1.add(Integer.parseInt(list.get(i)));
        }

        tabRoleMenuService.updRolePre(rid,list1);

        return Result.success(null);

    }

}
